package lc.递归;

/**
 * @description:
 * @author: qian
 * @createDate: 2021/10/30
 */
public class 剑指Offer64_求1加2加n {

    int res = 0;
    public int sumNums(int n) {

        return n < 0 ? 0 : n + sumNums(n - 1);
        //利用等差数列求和公式，Sn = na1+n(n-1)*d/2。
        //return n + n * (n - 1) / 2;
    }


}
